import { CHANGE_INPUT_VALUE, ADD_TODO_ITEM, REDUCE_TODO_ITEM, CHANGE_LIST_INFO } from './actionTypes'
import axios from 'axios'

export const getInputChangeValue = (value) => ({
  type: CHANGE_INPUT_VALUE,
  value
})

export const getAddTodoItem = () => ({
    type: ADD_TODO_ITEM
})

export const getReduceTodoItem = (index) => ({
  type: REDUCE_TODO_ITEM,
  index
})

export const getChangeListInfo = (data) => ({
  type: CHANGE_LIST_INFO,
  data
})

export const getListInfo = () => {
  return (dispatch) => {
    axios.get('/list.json').then((resp) => {
      const data = resp.data,
        action = getChangeListInfo(data)
        dispatch(action)
    }).catch((error) => {
      console.log(error)
    })
  }
}